<script>
	export default {
		globalData: {
			id: 0,
			// 胶囊距上距离
			menuTop: 0,
			// 导航栏高度
			navBarHeight: 0,
			// 胶囊距右方间距（保持左、右间距一致）
			menuRight: 0,
			// 胶囊距底部间距（保持底部间距一致）
			menuBotton: 0,
			// 胶囊高度（自定义内容可与胶囊高度保证一致）
			menuHeight: 0,
			// 状态栏高度
			statusBarHeight: 0,
			// 安全距离
			safeAreaHeight: 0,
			// 胶囊宽度
			menuWidth: 0,
		},
		onLaunch: function(option) {
			const that = this;
			// 获取系统信息
			wx.getSystemInfo({
				success: function(res) {
					// 状态栏高度
					that.globalData.statusBarHeight = res.statusBarHeight;
					// 屏幕宽度
					that.globalData.screenWidth = res.screenWidth;
					// 屏幕高度
					that.globalData.screenHeight = res.screenHeight;
				},
			});

			// 获取菜单按钮位置信息
			wx.getMenuButtonBoundingClientRect().then(res => {
				// 胶囊按钮位置信息
				that.globalData.menuTop = res.top;
				that.globalData.menuWidth = res.width;
				that.globalData.navBarHeight =
					(that.globalData.screenHeight - res.bottom) * 2 + res.height;
				that.globalData.menuRight = that.globalData.screenWidth - res.right;
				that.globalData.menuBotton = res.bottom;
				that.globalData.menuHeight = res.height;
				that.globalData.safeAreaHeight = res.safeAreaInsetsBottom || 0;
			});

			// 小程序主动更新
			this.updateManager();
		},
		methods: {
			/**
			 * 小程序主动更新
			 */
			updateManager() {
				const updateManager = wx.getUpdateManager();
				updateManager.onCheckForUpdate(res => {
					// 请求完新版本信息的回调
					// console.log(res.hasUpdate)
				});
				updateManager.onUpdateReady(() => {
					wx.showModal({
						title: '更新提示',
						content: '新版本已经准备好，即将重启应用',
						showCancel: false,
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						},
					});
				});
				updateManager.onUpdateFailed(() => {
					// 新的版本下载失败
					wx.showModal({
						title: '更新提示',
						content: '新版本下载失败',
						showCancel: false,
					});
				});
			},
		},
	};
</script>

<style lang="scss">
	/* 项目基础样式 */

	/* 解决小程序和app滚动条的问题 */
	/* #ifdef MP-WEIXIN || APP-PLUS */
	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}

	/* #endif */

	/* 解决H5 的问题 */
	/* #ifdef H5 */
	uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}

	/* #endif */
	.flex-row {
		display: flex;
		flex-direction: row;
	}

	.flex-col {
		display: flex;
		flex-direction: column;
	}

	.justify-start {
		justify-content: flex-start;
	}

	.justify-end {
		justify-content: flex-end;
	}

	.justify-center {
		justify-content: center;
	}

	.justify-between {
		justify-content: space-between;
	}

	.justify-around {
		justify-content: space-around;
	}

	.justify-evenly {
		justify-content: space-evenly;
	}

	.items-start {
		align-items: flex-start;
	}

	.items-end {
		align-items: flex-end;
	}

	.items-center {
		align-items: center;
	}

	.items-baseline {
		align-items: baseline;
	}

	.items-stretch {
		align-items: stretch;
	}

	.self-start {
		align-self: flex-start;
	}

	.self-end {
		align-self: flex-end;
	}

	.self-center {
		align-self: center;
	}

	.self-baseline {
		align-self: baseline;
	}

	.self-stretch {
		align-self: stretch;
	}

	.flex-1 {
		flex: 1 1 0%;
	}

	.flex-auto {
		flex: 1 1 auto;
	}

	.grow {
		flex-grow: 1;
	}

	.grow-0 {
		flex-grow: 0;
	}

	.shrink {
		flex-shrink: 1;
	}

	.shrink-0 {
		flex-shrink: 0;
	}

	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
	}
</style>